{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "received-interest",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.64679139 -0.39672087 -1.59326089 -0.343992   -1.73099992]\n",
      " [ 2.2993221   0.17277063 -1.82509207  1.1681846  -0.86437168]\n",
      " [ 0.33067461 -0.13482502  0.82173847  0.61172425 -1.83819785]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 1, -1, -1, -1, -1],\n",
       "       [ 1,  1, -1,  1, -1],\n",
       "       [ 1, -1,  1,  1, -1]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.random.randn(15).reshape((3,5))\n",
    "print(a)\n",
    "np.where(a>0, 1, -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "colonial-pierre",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.26411583  0.76626301  0.92767879  0.77316663 -0.66092697]\n",
      " [-0.94400428  0.62344844  0.07212818 -0.02506543 -0.91801303]\n",
      " [ 1.48039252 -0.64947627  0.943973    1.05970528  0.25069467]\n",
      " [-2.18945434  1.78741765 -0.72632874  0.24563135  1.19789275]\n",
      " [ 0.83272462 -0.27170389 -1.44955587 -1.94551488  0.03870986]\n",
      " [-0.33688087 -0.50198266  0.47000509  0.1051159   1.6483337 ]\n",
      " [-0.10989592  0.4893124   0.14307417 -1.31946353  0.46617309]\n",
      " [-1.34640974  0.73770618 -0.20789035 -0.11215145  0.7595645 ]\n",
      " [-0.52579958  1.31432835  0.95956042 -0.53908585  0.08962553]\n",
      " [ 1.15799409  2.19506325  0.02097737  0.0163959   0.34887559]\n",
      " [ 0.24755035 -0.32663299  2.11381713  0.57234299  0.88392993]\n",
      " [-0.33049684  1.30556576 -1.00980195  0.69917625  0.37891862]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  5, 10, 15],\n",
       "        [20, 25, 30, 35],\n",
       "        [40, 45, 50, 55]],\n",
       "\n",
       "       [[ 1,  6, 11, 16],\n",
       "        [21, 26, 31, 36],\n",
       "        [41, 46, 51, 56]],\n",
       "\n",
       "       [[ 2,  7, 12, 17],\n",
       "        [22, 27, 32, 37],\n",
       "        [42, 47, 52, 57]],\n",
       "\n",
       "       [[ 3,  8, 13, 18],\n",
       "        [23, 28, 33, 38],\n",
       "        [43, 48, 53, 58]],\n",
       "\n",
       "       [[ 4,  9, 14, 19],\n",
       "        [24, 29, 34, 39],\n",
       "        [44, 49, 54, 59]]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3. 变换形状\n",
    "a = np.random.randn(60).reshape((12,5))\n",
    "a.reshape((3,4,5))\n",
    "\n",
    "print(a)\n",
    "\n",
    "# 转置\n",
    "b = a.T\n",
    "b\n",
    "\n",
    "# 抽转换\n",
    "a = np.arange(60).reshape((3,4,5))\n",
    "b = a.transpose(2,0,1)\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "nasty-soldier",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.30284085  1.90766425  0.64222132  0.7898382  -1.47523159]\n",
      " [-0.75533903  0.86890516  0.51903134  0.73877055  1.38233535]\n",
      " [ 0.20993344 -0.24252821  0.45725061  0.14061422  1.25393998]\n",
      " [-0.51175412  0.6180418   0.37708615  0.34715868  0.1455248 ]\n",
      " [-0.10510986  0.43380106 -1.17066507 -1.09246    -0.17242105]\n",
      " [ 0.78278927 -0.23339426  1.6894519  -0.25947798  1.3506676 ]\n",
      " [ 1.00568628  0.40161539  1.1326863  -1.42503717  0.37424321]\n",
      " [-0.18208942  0.6293043   0.52955914 -0.26635114 -0.08490701]\n",
      " [ 0.20966431  0.73058979  0.0828018  -0.75804584  1.53504789]\n",
      " [ 1.4250904  -1.69523211 -0.35006605 -0.69236311  1.57361393]\n",
      " [ 1.39847982  0.62099094  2.01265888 -0.29925307  0.4803418 ]\n",
      " [ 2.11660189  0.36083973 -1.18570144  0.87557686 -1.25516581]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[-0.30284085, -0.75533903,  0.20993344, -0.51175412, -0.10510986,\n",
       "         0.78278927,  1.00568628, -0.18208942,  0.20966431,  1.4250904 ,\n",
       "         1.39847982,  2.11660189],\n",
       "       [ 1.90766425,  0.86890516, -0.24252821,  0.6180418 ,  0.43380106,\n",
       "        -0.23339426,  0.40161539,  0.6293043 ,  0.73058979, -1.69523211,\n",
       "         0.62099094,  0.36083973],\n",
       "       [ 0.64222132,  0.51903134,  0.45725061,  0.37708615, -1.17066507,\n",
       "         1.6894519 ,  1.1326863 ,  0.52955914,  0.0828018 , -0.35006605,\n",
       "         2.01265888, -1.18570144],\n",
       "       [ 0.7898382 ,  0.73877055,  0.14061422,  0.34715868, -1.09246   ,\n",
       "        -0.25947798, -1.42503717, -0.26635114, -0.75804584, -0.69236311,\n",
       "        -0.29925307,  0.87557686],\n",
       "       [-1.47523159,  1.38233535,  1.25393998,  0.1455248 , -0.17242105,\n",
       "         1.3506676 ,  0.37424321, -0.08490701,  1.53504789,  1.57361393,\n",
       "         0.4803418 , -1.25516581]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3. 变换形状\n",
    "a = np.random.randn(60).reshape((12,5))\n",
    "print(a)\n",
    "a.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "guilty-valley",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0  1  2  3  4]\n",
      "  [ 5  6  7  8  9]\n",
      "  [10 11 12 13 14]\n",
      "  [15 16 17 18 19]]\n",
      "\n",
      " [[20 21 22 23 24]\n",
      "  [25 26 27 28 29]\n",
      "  [30 31 32 33 34]\n",
      "  [35 36 37 38 39]]\n",
      "\n",
      " [[40 41 42 43 44]\n",
      "  [45 46 47 48 49]\n",
      "  [50 51 52 53 54]\n",
      "  [55 56 57 58 59]]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  5, 10, 15],\n",
       "        [20, 25, 30, 35],\n",
       "        [40, 45, 50, 55]],\n",
       "\n",
       "       [[ 1,  6, 11, 16],\n",
       "        [21, 26, 31, 36],\n",
       "        [41, 46, 51, 56]],\n",
       "\n",
       "       [[ 2,  7, 12, 17],\n",
       "        [22, 27, 32, 37],\n",
       "        [42, 47, 52, 57]],\n",
       "\n",
       "       [[ 3,  8, 13, 18],\n",
       "        [23, 28, 33, 38],\n",
       "        [43, 48, 53, 58]],\n",
       "\n",
       "       [[ 4,  9, 14, 19],\n",
       "        [24, 29, 34, 39],\n",
       "        [44, 49, 54, 59]]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(60).reshape((3,4,5))\n",
    "print(a)\n",
    "a.transpose(2,0,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "serious-cambodia",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-2.80762699, -1.17649565, -0.24601212,  0.0725334 ,  0.09116352,\n",
       "        0.39897957,  0.73565958,  0.96445003,  1.16428762,  1.80379649])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.random.randn(10)\n",
    "a.sort()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "minimal-chrome",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.48467793 -0.18847549 -1.35328848  0.78649857 -0.36934287]\n",
      " [ 1.43009564 -0.34346283 -1.51294475  1.18367158 -1.4171491 ]]\n",
      "[[-1.35328848 -0.36934287 -0.18847549  0.78649857  1.48467793]\n",
      " [-1.51294475 -1.4171491  -0.34346283  1.18367158  1.43009564]]\n"
     ]
    }
   ],
   "source": [
    "a = np.random.randn(10).reshape((2,5))\n",
    "print(a)\n",
    "a.sort(1)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "clean-monkey",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
